import { combineReducers } from 'redux';
// 导入action-types
import { GET_MESSAGE, ADD_MESSAGE, DEL_MESSAGE } from './action-types';
const initData = [];
function message(state=initData, action) {
    switch (action.type) {
        case GET_MESSAGE:
            return action.data;
            break;
        case ADD_MESSAGE:
            const arr=[...state];
            const id=arr.length>0?arr[0].id+1:1;
            arr.unshift({id,...action.data});
            return arr;
            break;
        case DEL_MESSAGE:
            return state.filter(item=>item.id!==action.data);
            break;
        default:
            return state;
    }
}

export default combineReducers({message});